package com.zmj.aspectj;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


@Component
// 该注解 标识这是个aop类
@Aspect
public class LogAop {

    Logger log= LogManager.getLogger(LoggerAspectj.class);
    /**
     * 切入被该注解标志的方法切入
     */
    @Pointcut("@annotation(com.zmj.utils.Log)")
    public void logPointcut() {

    }

    /**
     * 前置切入
     */
    @Before("logPointcut()")
    public void doBefore(JoinPoint joinPoint) {

        log.info("这个是一个前置通知:要纪录一下方法的名称"+ joinPoint.getTarget().toString() +":"+ joinPoint.getSignature().getName());

    }

    /**
     * 后置切入
     */
   /* @AfterReturning(returning = "obj", value = "logPointcut()")
    public void doAfter(Object obj,JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        log.info("这个是一个前置通知:要纪录一下方法的名称"+ joinPoint.getTarget().toString() +":"+ joinPoint.getSignature().getName() +" end......result:"+obj);
    }*/

}

